<?php

include "../unittests.php";

$db = new Db();
Assert::isDbLink($db->getLink());

$tablename = uniqid("tab");

/*
 * CREATE
 */
$result = $db->query("CREATE TABLE `$tablename` (
first char(50),
last char(50),
gender char(1),
birth DATE)");
Assert::isTrue($result->valid(), $result->errorMessage());

$result = $db->query("INSERT INTO $tablename (first, last, gender, birth)
VALUES ('bla', 'foo', 'm', NOW())");
Assert::isTrue($result->valid(), $result->errorMessage());

$result = $db->query("SELECT first, last, gender FROM $tablename WHERE first = 'bla'");
Assert::isTrue($result instanceof Db_Statement_mysql);
Assert::isTrue($result->valid());

foreach ($result as $value)
{
	Assert::isTrue($value["first"] == "bla");
	Assert::isTrue($value["last"] == "foo");
	Assert::isTrue($value["gender"] == "m");
}

/*
 * DELETE
 */
$result = $db->query("DROP TABLE $tablename");
Assert::isTrue($result->valid(), $result->errorMessage());